package com.gx.smart.building.ui.assets

import android.text.Editable
import android.view.ViewGroup
import com.gx.smart.base.BaseMVVMActivityV3
import com.gx.smart.building.R
import com.gx.smart.building.databinding.ActivityAssetsMaintainDetailBinding
import com.gx.smart.building.ui.assets.viewmodel.AssetsViewModel
import com.gx.smart.building.ui.common.adapter.ImageAdapter
import com.gx.smart.building.ui.maintain.adapter.MaintainResultAdapter
import com.gx.smart.lib_http.BuildConfig

class AssetsMaintainDetailActivity : BaseMVVMActivityV3<AssetsViewModel>() {
    private lateinit var viewBinding: ActivityAssetsMaintainDetailBinding
    override fun onBindViewModel(): Class<AssetsViewModel> = AssetsViewModel::class.java

    override fun onBindLayout(): Int = R.layout.activity_assets_maintain_detail

    override fun getToolbarTitle(): String = "资产详情"

    override fun initContentView(root: ViewGroup) {
        viewBinding = ActivityAssetsMaintainDetailBinding.inflate(layoutInflater, root, true)
    }
    override fun initData() {
        val assetId = intent.getStringExtra("assetId")
        val planTaskId = intent.getStringExtra("planTaskId")
        viewModel.queryPlanTaskAssetDetail(planTaskId!!, assetId!!)
        viewModel.assetDetail.observe(this) {
            viewBinding.assetTypeCode.text = it.assetTypeCode
            viewBinding.assetName.text = it.assetName
            viewBinding.assetTypeName.text = it.assetTypeName
            viewBinding.brandName.text = it.brandName
            viewBinding.modelName.text = it.modelName
            viewBinding.areaName.text = it.areaName
            viewBinding.resultDesc.apply {
                text = Editable.Factory.getInstance().newEditable(it.resultDesc)
            }
        }
        val imageAdapter = ImageAdapter(this)
        viewBinding.imageRecyclerView.adapter = imageAdapter
        viewModel.detailFileList.observe(this) { it ->
            imageAdapter.addAll(it.map {
                BuildConfig.FILE_UPLOAD_URL + it.fileUrl
            })
        }
        //状态：1-已处理，2-未处理
        val resultAdapter =
            MaintainResultAdapter(
                this, 1, null, null,
                null, null
            )
        viewBinding.resultRecyclerView.adapter = resultAdapter
        viewModel.detailResultList.observe(this) { it ->
            resultAdapter.refresh(it)
        }
    }
}